package utils

import (
	"crypto/md5"
	"fmt"
	"golang.org/x/crypto/bcrypt"
)

func HashAndSalt(pwd string) string {
	data := []byte(pwd)
	hash, err := bcrypt.GenerateFromPassword(data, 9)
	if err != nil {
		return ""
	}
	return string(hash)
}
func ComparePasswords(hashedPwd string, plainPwd string) bool {

	byteHash := []byte(hashedPwd)
	err := bcrypt.CompareHashAndPassword(byteHash, []byte(plainPwd))
	if err != nil {
		return false
	}
	return true
}

func Md5(data string) string {
	has := md5.Sum([]byte(data))
	md5str1 := fmt.Sprintf("%x", has)
	return md5str1
}
